<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>类字段</title>
</head>
<body>
<script>
    class User {
        age = 12

        constructor(name) {
            this.name = name
            /*
               定义成类字段的话本质就像下面这样

               this.age = 12
                 this.getName = function (){
                     return this.name
                 }*/
        }

        getName = function () {
            return this.name
        }
    }

    let user = new User()
    console.log(user)

</script>
</body>
</html>